﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Application.Admin.Article
{
    public class ArticleInfoClassService : IArticleInfoClassService
    {
        Domain.Uow.IRepository<Domain.Entity.ArticleInfoClass> articleInfoClassRepository;

        public ArticleInfoClassService(Domain.Uow.IRepository<Domain.Entity.ArticleInfoClass> ArticleInfoClass)
        {
            if (ArticleInfoClass == null)
            {
                throw new ArgumentNullException("articleInfoClassRepository is null");
            }
            articleInfoClassRepository = ArticleInfoClass;
        }

        public Domain.Entity.ArticleInfoClass Add(Domain.Entity.ArticleInfoClass add, Domain.Entity.User operUser)
        {
            if (add == null) return add;
            articleInfoClassRepository.Add(add);
            articleInfoClassRepository.Uow.Commit();
            return add;
        }

        public bool Delete(Domain.Entity.ArticleInfoClass delete, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                delete.State = false;
                articleInfoClassRepository.Modify(delete);
                articleInfoClassRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool DeleteTrue(Domain.Entity.ArticleInfoClass delete, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                articleInfoClassRepository.Delete(delete);
                articleInfoClassRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool Delete(IList<int> idList, Domain.Entity.User operUser)
        {
            var res = false;
            var delete = articleInfoClassRepository.GetList(e => idList.Contains(e.Id));
            foreach (var item in delete)
            {
                item.State = false;
                articleInfoClassRepository.Modify(item);
            }
            try
            {
                articleInfoClassRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool DeleteTrue(IList<int> idList, Domain.Entity.User operUser)
        {
            var res = false;
            var delete = articleInfoClassRepository.GetList(e => idList.Contains(e.Id));
            foreach (var item in delete)
            {
                articleInfoClassRepository.Delete(item);
            }
            try
            {
                articleInfoClassRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool Modify(Domain.Entity.ArticleInfoClass modify, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                articleInfoClassRepository.Modify(modify);
                articleInfoClassRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public Domain.Entity.ArticleInfoClass Get(int id)
        {
            var data = articleInfoClassRepository.Get(id);
            return data;
        }

        public IQueryable<Domain.Entity.ArticleInfoClass> GetList()
        {
            var data = articleInfoClassRepository.GetList();
            return data;
        }

    }
}
